package com.ftn;

import java.awt.*;

/**
 * User: Jack Fu
 * Date: 2024/9/5
 * Time: 15:39
 * To change this template use File | Settings | File Templates.
 * Description:
 */
public class Enemy1Obj extends GameObj{

    int removeX = -1500;
    int removeY = -1500;

    public Enemy1Obj() {
    }

    public Enemy1Obj(int x, int y, int width, int height, Image image, int speed, GameWin gameWin) {
        super(x, y, width, height, image, speed, gameWin);
    }

    public Enemy1Obj(int x, int y, Image image, int speed) {
        super(x, y, image, speed);
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        y += this.getSpeed();

        // 与我方子弹碰撞后，直接消失
        for (ShellObj shellObj : GameUtils.shellObjs) {
            if (this.getRec().intersects(shellObj.getRec())) {
                // 添加爆炸对象
                ExplodeObj explodeObj = new ExplodeObj(this.getX(), this.getY());
                GameUtils.explodeObjs.add(explodeObj);
                GameUtils.removeObjs.add(explodeObj);

                this.setX(removeX);
                shellObj.setX(removeY);
                GameUtils.removeObjs.add(this);
                GameUtils.removeObjs.add(shellObj);

                GameWin.score += 5;
            }
        }

        if (this.getY() > 1000) {
            GameUtils.removeObjs.add(this);
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
